package com.yunkeji.api.test;

import com.yunkeji.common.msg.utils.BadWordDetectorUtils;
import org.ahocorasick.trie.Emit;
import org.ahocorasick.trie.Trie;

import java.util.Collection;
import java.util.Set;
import java.util.TreeSet;

public class AhoCorasickExample {
    public static void main(String[] args) {
        Set<String> badWords = new TreeSet<>();
        badWords.add("f");
        badWords.add("h");

        Trie.TrieBuilder builder = Trie.builder();
        for (String word : badWords) {
            builder = builder.addKeyword(word);
        }
        Collection<Emit> fhh1 = builder.build().parseText("fhh");
        for (Emit emit : fhh1) {
            System.err.println("777" + emit.getKeyword());
        }

        BadWordDetectorUtils badWordDetectorUtils = new BadWordDetectorUtils(badWords);
        Set<String> fhh = badWordDetectorUtils.getBadWords("fhh");

        System.err.println(fhh);

        Trie trie = Trie.builder().addKeyword("f").addKeyword("h").build();
        String text = "fhh";
        Collection<Emit> emits = trie.parseText(text);
        for (Emit emit : emits) {
            System.err.println(emit.getKeyword());
        }
    }
}
